<?php


namespace app\admin\controller;


use app\service\orderService;
use think\db\Where;
use think\facade\Db;
use think\facade\View;

class Bill extends Common
{
    public function billList(){
        $adminId = session('id');
        $usertype = Db::name('admin')->where('id',$adminId)->value('usertype');
        View::assign('usertype',$usertype);
        //根据当前账号查询区域
        $com = $this->pidTokenId();
        $whe=new Where();
        //$com['community_id']=implode(',',$com['community_id']);
        $whe['id'] = array('in',$com['parking_id']);

        //根据账号查询停车场
        $parkinglist = (new orderService())->parkingList($whe);

        View::assign('parkinglist',$parkinglist);
        //$parkingNo = $this->getParkingNo();
        //搜索
        $data = request()->get();
        //var_dump($data);
        //$where=new Where();
        $where=array();
        $clientList=array();
        if (!empty($data)){

            if(!empty($data['plateNumber'])){
                //echo 2;carPlateNo
                //$where['carPlateNo'] = $data['carPlateNo'];
                $where[]=['plateNumber','like','%'.$data['plateNumber'].'%'];
            }


        }
        View::assign("clientList",$clientList);
        //var_dump($where);
        //$where=array_filter($where);
        $export = $where;
        $export = json_encode($export);
        $export = str_replace("\"","|",$export);
        View::assign('export',$export);
        $page = request()->has('page') ? request()->get('page') : 1;
        //多条件查询地库车位信息

        $query=array_filter($data);
        $orderlist =Db::name('cxyun_pay_bill')
            ->order("id desc")
            ->paginate(100, false, [
                'page'  =>  $page,
                'query' =>  $query
            ]);
        $list=[];
        foreach ($orderlist as $info){
            $roominfo=Db::table("roominfo")->where("id",$info["room_id"])->find();
            if(empty($roominfo)){
                $info["address"]='';
            }else{
                $info["address"]=$roominfo["group"].$roominfo["building"]."-".$roominfo["unit"]."-".$roominfo["room"];

            }
            $info["addfess"]=$roominfo["group"].$roominfo["building"]."-".$roominfo["unit"]."-".$roominfo["room"];
            $list[]=$info;
        }

        $number = Db::name('cxyun_pay_bill')

            ->where($where)->count();
        View::assign('number',$number);
        View::assign('list',$list);
        View::assign('orderlist',$orderlist);
        foreach ($data as $k => $v) {
            View::assign($k, $v);

        }
        return  View::fetch('bill_list');
    }

}